<!-- 添加商品 -->
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>书瞳-添加商品</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="__ROOT__/public/static/admin/css/font.css">
    <link rel="stylesheet" href="__ROOT__/public/static/admin/css/xadmin.css">
    <link rel="stylesheet" href="__ROOT__/public/static/admin/css/shop-add.css">
    <script src="__ROOT__/public/static/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="__ROOT__/public/static/admin/js/xadmin.js"></script>
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">商品管理</a>
            <a>
                <cite>编辑商品</cite></a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
            onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5 shop-add-form"
                            action="{:url('shop/editBook')}" method="post" enctype="multipart/form-data">
                            <div class="shop-add-left">
                                <div class="layui-input-inline layui-show-xs-block row">
                                    <label for="">商品名称:</label>
                                    <input type="text" name="bookID" autocomplete="off" class="layui-input"
                                        value="{$book.bookID}" style="display:none">
                                    <input type="text" name="bname" autocomplete="off" class="layui-input"
                                        value="{$book.bname}"></div>

                                <div class="layui-input-inline layui-show-xs-block row">
                                    <label for="">商品描述:</label>
                                    <textarea type="textarea" name="shuoming" autocomplete="off"
                                        class="layui-textarea">{$book.shuoming}</textarea></div>

                                <div class="layui-input-inline layui-show-xs-block row">
                                    <label for="">商品类别:</label>
                                    <select name="bclass">
                                        <option>{$book.bclass}</option>
                                        {foreach $bclasses as $bclass}
                                        <option>{$bclass.bclass}</option>
                                        {/foreach}
                                    </select>

                                </div>

                                <div class="layui-input-inline layui-show-xs-block row">
                                    <label for="">库存:</label>
                                    <input type="number" name="storenum" autocomplete="off" min="1" max="9999"
                                        class="layui-input" value="{$book.storenum}"></div>

                                <div class="layui-input-inline layui-show-xs-block row">
                                    <label for="">原价:</label>
                                    <input type="number" name="price" autocomplete="off" min="1.00" max="9999.99"
                                        step="0.01" class="layui-input" value="{$book.price}"></div>

                                <div class="layui-input-inline layui-show-xs-block row">
                                    <label for="">现价:</label>
                                    <input type="number" name="yourprice" autocomplete="off" min="1.00" max="9999.99"
                                        step="0.01" class="layui-input" value="{$book.yourprice}"></div>

                            </div>


                            <div class="shop-add-right">
                                <div class="row">
                                    <span>商品缩略图200*200:</span>
                                    <div class="fileBox">
                                        <input type="file" name="pictures" size="24" class="inputfile" id="pictures"
                                            onchange="changepic(this)"
                                            accept="image/png, image/jpeg, image/gif, image/jpg">
                                        <label for="pictures">
                                            <span class="add">+</span>
                                            <span class="font">点击上传图片</span>
                                            {if condition="$book.pictures neq null"}
                                            <img src="__ROOT__/public/static/image/{$book.pictures}" alt=""
                                                class="show pictures">
                                            {else /}
                                            <img src="" alt="" class="show pictures">
                                            {/if}
                                        </label>
                                    </div>

                                </div>


                                <div class="row">
                                    <span>商品缩略图350*350:</span>
                                    <div class="fileBox">
                                        <input type="file" name="picturem" size="24" class="inputfile" id="picturem"
                                            onchange="changepic(this)"
                                            accept="image/png, image/jpeg, image/gif, image/jpg">
                                        <label for="picturem">
                                            <span class="add">+</span>
                                            <span class="font">点击上传图片</span>
                                            {if condition="$book.picturem neq null"}
                                            <img src="__ROOT__/public/static/image/{$book.picturem}" alt=""
                                                class="show picturem">
                                            {else /}
                                            <img src="" alt="" class="show picturem">
                                            {/if}
                                        </label>
                                    </div>
                                </div>
                                <div class="row">
                                    <span>商品缩略图350*350（可选）:</span>
                                    <div class="fileBox">
                                        <input type="file" name="pictureb" size="24" class="inputfile" id="pictureb"
                                            onchange="changepic(this)"
                                            accept="image/png, image/jpeg, image/gif, image/jpg">
                                        <label for="pictureb">
                                            <span class="add">+</span>
                                            <span class="font">点击上传图片</span>
                                            {if condition="$book.pictureb neq null"}
                                            <img src="__ROOT__/public/static/image/{$book.pictureb}" alt=""
                                                class="show pictureb">
                                            {else /}
                                            <img src="" alt="" class="show pictureb">
                                            {/if}
                                        </label>
                                    </div>
                                </div>
                            </div>

                            <div class="shop-add-btn">
                                <input class="layui-btn" lay-filter="add" type="submit" value="确定">
                            </div>

                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="__ROOT__public/static/js/jquery-1.8.3.min.js"></script>
<script>
    function changepic(obj) {
        //console.log(obj.files[0]);//这里可以获取上传文件的name
        var newsrc = getObjectURL(obj.files[0]);
        
        let id = $(obj).attr('id');
        $('.'+id).prop('src', newsrc);
        // document.getElementById('show').src = newsrc;
    }
    //建立一個可存取到該file的url
    function getObjectURL(file) {
        var url = null;
        // 下面函数执行的效果是一样的，只是需要针对不同的浏览器执行不同的 js 函数而已
        if (window.createObjectURL != undefined) { // basic
            url = window.createObjectURL(file);
        } else if (window.URL != undefined) { // mozilla(firefox)
            url = window.URL.createObjectURL(file);
        } else if (window.webkitURL != undefined) { // webkit or chrome
            url = window.webkitURL.createObjectURL(file);
        }
        return url;
    }
</script>

<script>layui.use(['laydate', 'form'],
        function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });
        });


    /*用户-停用*/
    function member_stop(obj, id) {
        layer.confirm('确认要停用吗？',
            function (index) {

                if ($(obj).attr('title') == '启用') {

                    //发异步把用户状态进行更改
                    $(obj).attr('title', '停用');
                    $(obj).find('i').html('&#xe62f;');

                    $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                    layer.msg('已停用!', {
                        icon: 5,
                        time: 1000
                    });

                } else {
                    $(obj).attr('title', '启用');
                    $(obj).find('i').html('&#xe601;');

                    $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                    layer.msg('已启用!', {
                        icon: 5,
                        time: 1000
                    });
                }

            });
    }

    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？',
            function (index) {
                //发异步删除数据
                $(obj).parents("tr").remove();
                layer.msg('已删除!', {
                    icon: 1,
                    time: 1000
                });
            });
    }

    function delAll(argument) {

        var data = tableCheck.getData();

        layer.confirm('确认要删除吗？' + data,
            function (index) {
                //捉到所有被选中的，发异步进行删除
                layer.msg('删除成功', {
                    icon: 1
                });
                $(".layui-form-checked").not('.header').parents('tr').remove();
            });
    }</script>

</html>